package com.sky.mapper.admin;

import com.github.pagehelper.Page;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.pojo.Dish;
import com.sky.pojo.DishFlavor;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description DishMapper
 * @Author luohai
 * @Date 2024-09-30
 */
@Mapper
public interface DishMapper {

    @Select("select * from dish_flavor where dish_id = #{id}")
    List<DishFlavor> getByDishId(Long id);
    /**
     * 添加菜品
     * @param dish
     * @return
     */
    //能够在service层获取到id
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into dish(name, category_id, price, image, description, create_time, update_time, create_user, update_user, make_time) VALUES (#{name},#{categoryId},#{price},#{image},#{description},#{createTime},#{updateTime},#{createUser},#{updateUser},#{makeTime})")
    void addDish(Dish dish);

    /**
     * 添加菜品口味
     * @param dishId
     * @param name
     * @param value
     */
    @Insert("insert into dish_flavor (dish_id, name, value) values (#{dishId},#{name},#{value})")
    void addFlavors(Long dishId, String name, String value);

    /**
     * 菜品分页查询
     * @param dishPageQueryDTO
     * @return
     */
    List<DishVO> searchAllDish(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 菜品批量删除
     * @param ids
     * @return
     */
    void deleteDishesById(List<Long> ids);

    /**
     * 根据ID查询菜品（数据回显）
     * @return
     */

    DishVO searchDishById(Integer dishId);

    /**
     * 根据ID修改菜品
     * @param dish
     * @return
     */
    @Options(keyProperty = "id",useGeneratedKeys = true)
    void modifyDishesById(Dish dish);

    /**
     * 根据ID修改口味
     * @param
     */
    void modifyFlavors(Long dishId,String name,String value);

    /**
     * 根据dish_id
     * @param id
     */
    @Delete("delete from dish_flavor where dish_id = #{id}")
    void deleteflavorsById(Long id);

    /**
     * 根据dishID查询口味
     * @param dishId
     * @return
     */
    @Select("select * from dish_flavor where dish_id = #{dishId}")
    List searchFlavorsById(Integer dishId);

    /**
     * 根据分类id查询菜品
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId}")
    List<DishVO> queryDishesByCategoryId(Long categoryId);


    List<Dish> list(Dish dish);
}
